/*
 * Copyright (C) 2017 The MoonLake Authors
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */


package com.minecraft.moonlake.legendaryweaponrel.weapons.tool;

import com.minecraft.moonlake.legendaryweaponrel.weapons.WeaponAbstractEntityDamageByEntity;
import org.bukkit.Material;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;

public class Storm extends WeaponAbstractEntityDamageByEntity {

    public Storm() {
        super("storm", "&b虹吸剑", Material.IRON_SWORD);
    }

    @Override
    public String[] getLore() {
        return new String[] {
                "&7每次击中目标玩家将减少目标 &a1 &7格饱食度"
        };
    }

    @Override
    protected void onDamage(EntityDamageByEntityEvent event, Player player, LivingEntity entity) {
        if(!(entity instanceof Player)) return; // 如果受伤实体不是玩家则返回
        Player target = (Player) entity;

        if(target.getFoodLevel() <= 2) target.setFoodLevel(0); // 如果当前饱食度小于等于 2 则直接清除
        else target.setFoodLevel(target.getFoodLevel() - 2); // 否则设置饱食度等于当前饱食度减 2
    }
}
